﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Alex2
{
    class InGameGUI
    {
        private SpriteFont font;
        private Vector2 inventoryPos;
        private Texture2D inventoryBar;
        private Rectangle inventoryBarBox, mouseBox;
        private MouseState mouse;
        private bool hidden,downAnimDone,upAnimDone;
        public InGameGUI(Texture2D ibar, SpriteFont f) {
            inventoryBar = ibar;
            font = f;
            hidden = true;
            downAnimDone = true;
            upAnimDone = true;
            inventoryBarBox = new Rectangle(624, 2, 80, 20);
            mouseBox = new Rectangle(0, 0, 30, 30);
            inventoryPos = new Vector2(85, -120); 
        }

        public void Update(GameTime gameTime) {
            mouse = Mouse.GetState();
            mouseBox.X = mouse.X;
            mouseBox.Y = mouse.Y;

            intersectInventory();
            
            if (!downAnimDone && upAnimDone) {
                inventoryDownAnimation();
            }
            else if (!upAnimDone && downAnimDone) {
                inventoryUpAnimation();
            }
        }

        private void intersectInventory() {
            if (mouseBox.Intersects(inventoryBarBox) && mouse.LeftButton == ButtonState.Pressed && hidden && upAnimDone) {
                hidden = false;
                downAnimDone = false;
                inventoryDownAnimation();
            }
            else if (mouseBox.Intersects(inventoryBarBox) && mouse.LeftButton == ButtonState.Pressed && !hidden && downAnimDone) {
                hidden = true;
                upAnimDone = false;
                inventoryUpAnimation();
            }

        }

        private void inventoryDownAnimation() {
            if (inventoryPos.Y <= 10)
            {
                inventoryPos.Y += 5;
            }
            else {
                inventoryBarBox.Y = 130;
                downAnimDone = true;
            }
        }

        private void inventoryUpAnimation() {
            if (inventoryPos.Y >= -120)
            {
                inventoryPos.Y -= 5;
            }
            else {
                inventoryBarBox.Y = 2;
                upAnimDone = true;
            }
        }

        public void Draw(SpriteBatch spriteBatch) {
            spriteBatch.Draw(inventoryBar, inventoryPos, Color.White);
            spriteBatch.DrawString(font, "hidden:" + hidden, new Vector2(50.0f, 550.0f), Color.White);
            spriteBatch.DrawString(font, "mouseB X:" + mouseBox.X + "mouseB Y:" + mouseBox.Y, new Vector2(50.0f, 650.0f), Color.Red);
        
        }

    }
}
